from classfile import class_reader


class ClassFile:
    minorVersion = 0
    majorVersion = 0
    constantPool = 0
    accessFlags = 0
    thisClass = 0
    superClass = 0
    interfaces = []
    fields = []
    methods = []
    attributes = []

    def read(self,reader):
        self.readAndCheckMagic(reader)
        self.readAndCheckVersion(reader)        

    def readAndCheckMagic(self,reader):
        magic =reader.readUnit32()
        
        if magic != b'\xca\xfe\xba\xbe':
            raise Exception("java.lang.ClassFormatError:magic!")
        print(magic)
        
    def readAndCheckVersion(self,reader):
        self.minorVersion=reader.readUnit16()
        print(self.minorVersion)

    def parse(self, data):
        reader = class_reader.ClassReader()
        reader.data=data
        self.read(reader)